/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package common;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

/**
 *
 * @author Administrator
 */

public class PasswordValidator implements Validator{
  public void validate(FacesContext context, UIComponent component, Object pass) throws ValidatorException {

    if(!(pass instanceof String)){
        FacesMessage message = new FacesMessage();
        message.setSummary("* Errore irreversibile");
        throw new ValidatorException(message);
    }
    String password = (String) pass;
    //verifico che non sia vuoto
    if(password.length()==0){
        FacesMessage message = new FacesMessage();
        message.setSummary("* Devi inserire una Password");
        throw new ValidatorException(message);
    }
    //verifico che sia superiore a 3
    if (password.length() < 2){
        FacesMessage message = new FacesMessage();
        message.setSummary("* La Password deve avere almeno 3 caratteri");
        throw new ValidatorException(message);
    }
  }
}
